﻿//-----------------------------------------------------------------------
// <copyright file="NotifyPropertyChanged.cs" company="Microsoft">
//     Copyright (c) AGALTIER, Microsoft. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace ArchiSimple.Windows.Tools
{
    using System;
    using System.Linq;
using System.ComponentModel;
using System.Linq.Expressions;

    /// <summary>
    /// TODO: Provide summary section in the documentation header.
    /// </summary>
    public static class NotifyPropertyChanged
    {
        public static void Notify<T, T2>(this T obj, Expression<Func<T, T2>> property, Action action)
            where T : INotifyPropertyChanged
        {
            string propertyName = (property.Body as MemberExpression).Member.Name;

            obj.PropertyChanged += (sender, e) =>
            {
                if (e.PropertyName == propertyName)
                {
                    action();
                }
            };
        }
    }
}
